package com.iman.manjusri.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.springframework.stereotype.Service;

import com.iman.common.support.Page;
import com.iman.manjusri.mappers.BlogMapper;
import com.iman.manjusri.service.BlogService;
import com.iman.manjusri.vo.BlogDetailVo;
import com.iman.manjusri.vo.BlogVo;

@Service
public class BlogServiceImpl implements BlogService {
	@Inject
	private BlogMapper blogMapper;

	@Override
	public Page<BlogVo> getBlogList(int type, int ps, int pn) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("offset", (pn - 1) * ps);
		params.put("limit", ps);
		Page<BlogVo> pages = new Page<BlogVo>();
		int totalCount = 0;
		List<BlogVo> result = null;
		if (type == 1) { // 全部
			totalCount = blogMapper.getblog(null).size();
			result = blogMapper.getblog(params);
			pages.setData(result);
			pages.setPageSize(ps);
			pages.setStart((pn - 1) * ps);
			pages.setTotalCount(totalCount);
		} else if (type == 2) {// 推荐
			totalCount = blogMapper.getrecommendblog(null).size();
			result = blogMapper.getrecommendblog(params);
			pages.setData(result);
			pages.setPageSize(ps);
			pages.setStart((pn - 1) * ps);
			pages.setTotalCount(totalCount);
		} else if (type == 3) { // 精华
			totalCount = blogMapper.getEssenceBlog(null).size();
			result = blogMapper.getEssenceBlog(params);
			pages.setData(result);
			pages.setPageSize(ps);
			pages.setStart((pn - 1) * ps);
			pages.setTotalCount(totalCount);
		}
		return pages;
	}

	@Override
	public BlogDetailVo getBlogDetal(String blogId) {
		return null;
	}

}
